package com.mnsq.user.controller;

import com.mnsq.common.bean.annotation.UserInfoRequired;
import com.mnsq.common.bean.conf.ThreadLocalInfo;
import com.mnsq.common.bean.dto.LoginInfo;
import com.mnsq.user.bean.condition.AccountCondition;
import com.mnsq.user.service.AccountService;
import matrix.module.common.bean.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Administrator
 * @date 2019/3/18 0018
 */
@Api("用户账号相关接口")
@RestController
@RequestMapping("/api/account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @ApiOperation("用户注册")
    @PostMapping("register")
    public Result register(@RequestBody AccountCondition ac) {
        return accountService.register(ac);
    }

    @ApiOperation("判断用户是否存在")
    @PostMapping("/whether/exist")
    public Result exist(@RequestBody AccountCondition ac) {
        return accountService.existAccount(ac);
    }

    @ApiOperation("绑定用户第三方账号")
    @PostMapping("bind")
    public Result bind(@RequestBody AccountCondition ac) {
        return accountService.bind(ac);
    }

    @ApiOperation("用户登录")
    @PostMapping("login")
    public Result login(@RequestBody AccountCondition ac) {
        return accountService.login(ac);
    }

    @ApiOperation("用户退出登录")
    @UserInfoRequired(true)
    @PostMapping("logout")
    public Result logout(){
        LoginInfo loginInfo = ThreadLocalInfo.LOGIN_INFO.get();
        return accountService.logout(loginInfo.getToken());
    }
}
